package cn.melonlib.cores.jpa.comp.web.ctrl;

import cn.melonlib.cores.jpa.comp.Dao;
import cn.melonlib.cores.jpa.comp.dao.db.DatabaseSchemasCreator;
import cn.melonlib.cores.jpa.model.entity.DbTableUpdateLog;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Component
public class DbCreatorLogWebProxy {

    @Resource
    private Dao dao;

    @Resource
    private DatabaseSchemasCreator databaseSchemasCreator;

    public List<DbTableUpdateLog> createDbSchemas(){
        return dao.getAllTypes().values().stream().map(type->{
            System.out.println(type.getBindableJavaType().getName());
            try {
                return this.databaseSchemasCreator.createEntitySchema(type.getBindableJavaType());
            } catch (Exception exception) {
               throw new RuntimeException(exception);
            }
        }).toList();
    }
}
